<template>
  <footer class="footer">
    <span class="todo-count">剩余<strong>数量值</strong>{{ getSum }}</span>
    <ul class="filters">
      <li>
        <a
          @click="$emit('findList', 'all')"
          :class="{ selected: type === 'all' }"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          @click="$emit('findList', 'yes')"
          :class="{ selected: type === 'yes' }"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          @click="$emit('findList', 'no')"
          :class="{ selected: type === 'no' }"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clearAll">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
    type: {
      type: String,
      required: true,
    },
  },
  methods: {
    // 通知父组件清除已完成
    clearAll() {
      this.$emit("clearList");
    },
  },
  computed: {
    getSum() {
      // 计算剩余数量
      return this.list.filter((item) => !item.isDone).length;
    },
  },
};
</script>